﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width initial-scale=1.0, user-scalable=no" />
    <title>多tab联动实例</title>
    <meta name="Description" content="多tab联动实例 by noob" />
    <!-- Link Swiper's CSS -->
    <link rel="stylesheet" href="css/swiper.min.css">
    <!-- Demo styles -->
    <style>
        html, body {
            width: 100%;
            height: 100%;
            background: #eee;
            font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
            font-size: 14px;
            color: #000;
            margin: 0;
            padding: 0;
        }

        .main {
            position: relative;
            width: 100%;
            max-width: 540px;
            height: 100%;
            margin: 0 auto;
        }

        .tabs.swiper-container {
            position: absolute;
            left: 0px;
            top: 0px;
            width: 100%;
            height: 40px;
            line-height: 40px;
        }

        .tabs .swiper-slide {
            text-align: center;
            font-size: 18px;
            background: #fff;
            width: 25%;
            border-radius: 5px;
        }

            .tabs .swiper-slide.active {
                border: 2px solid #ff6a00;
                box-sizing: border-box;
            }

        #tabs-container {
            position: absolute;
            left: 0px;
            top: 50px;
            bottom: 0px;
            width: 100%;
            border: 2px solid #ff6a00;
            box-sizing: border-box;
            font-size: 24px;
        }
    </style>
</head>
<body>
    <div class="main">
        <!-- Swiper -->
        <div class="swiper-container tabs">
            <div class="swiper-wrapper">
                <div class="swiper-slide active">Slide 1</div>
                <div class="swiper-slide">Slide 2</div>
                <div class="swiper-slide">Slide 3</div>
                <div class="swiper-slide">Slide 4</div>
                <div class="swiper-slide">Slide 5</div>
                <div class="swiper-slide">Slide 6</div>
            </div>
        </div>
        <div class="swiper-container" id="tabs-container">
            <div class="swiper-wrapper">
                <div class="swiper-slide">Slide 1</div>
                <div class="swiper-slide">Slide 2</div>
                <div class="swiper-slide">Slide 3</div>
                <div class="swiper-slide">Slide 4</div>
                <div class="swiper-slide">Slide 5</div>
                <div class="swiper-slide">Slide 6</div>
            </div>
        </div>
    </div>
    <!-- Swiper JS -->
    <script src="http://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    <script src="js/swiper.min.js"></script>
    <!-- Initialize Swiper -->
    <script>
        var mySwiper = new Swiper('.tabs', {
            // freeMode: true,
            slidesPerView: 'auto',
            spaceBetween: 10
        });
        var tabsSwiper = new Swiper('#tabs-container', {
            speed: 500,
            initialSlide: 0,
            onSlideChangeStart: function (tabsSwiper) {
                var index = tabsSwiper.activeIndex;
                $(".tabs .active").removeClass('active');
                $(".tabs .swiper-slide").eq(index).addClass('active');
                mySwiper.slideTo(index);
            }
        });
        $(".tabs .swiper-slide").on('touchstart mousedown', function (e) {
            e.preventDefault();
            var $this = $(this);
            if (!$this.hasClass('active')) {
                $(".tabs .active").removeClass('active');
                $(this).addClass('active');
                tabsSwiper.slideTo($(this).index());
                mySwiper.slideTo($(this).index());
            }
        });
    </script>
</body>
</html>